﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MsForgeReboot.Framework.Entities;
using MsForgeReboot.Framework.Interfaces;

namespace MsForgeReboot.Services {
    public class TownCrierPersistenceService : ITownCrierPeristenceService {

        private readonly MsForgeContext _context;

        public TownCrierPersistenceService(MsForgeContext ctx) {
            this._context = ctx;
        }


        #region ITownCrierPeristenceService Members

        public IList<Cry> GetAllCries() {
            //throw new NotImplementedException();
            return this._context.Cries.ToList();
        }

        public Cry GetOneCry(int id) {
            //throw new NotImplementedException();
            return this._context.Cries.Single(c => c.Id == id);
        }

        public IList<CryStatistic> GetStatisticsForCry(int id) {
            //throw new NotImplementedException();
            return this._context.CryStatistics.Where(cs => cs.Cry.Id == id).ToList();
        }

        public IList<CryStatistic> GetStatisticsForCry(Cry entity) {
            return this.GetStatisticsForCry(entity.Id);
        }

        public void SaveCry(Cry entity) {
            //throw new NotImplementedException();
            this._context.Cries.Add(entity);
            this._context.SaveChanges();
        }

        public void Delete(Cry entity) {
            throw new NotImplementedException();
        }

        public void Delete(int id) {
            throw new NotImplementedException();
        }

        #endregion
    }
}
